
import java.util.Stack;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Lix
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        char er[] = "((a|(ab)*)|b)*".toCharArray();
        Stack stack = new Stack<Character>();
        int i = 0;
        int j = er.length-1;
        
        while(i!=j)
        {
            if(er[i]!='(' && er[i]!=')')
            {
                stack.push(er[i]);
                i++;
            }
            else if(er[j]!='(' && er[j]!=')')
            {
                stack.push(er[j]);
                j--;
            }
            else
            {
                i++;
                j--;
            }
        }
        stack.push(er[j]);
        
        while(!stack.empty())
        {
            System.out.println(stack.pop());
        }
    }
}
